// line = readline()
// var array = JSON.parse(line)

const { log } = require("console");
const { turquoise } = require("color-name");

//树的节点
class TreeNode {
    constructor(val) {
        this.val = val;
        this.left = this.right = null;
    }
}

function convertTree(arr) {
    // 在这里编写转换树的代码，并返回转换完的树
    if (arr.length == 0) {
        return {};
    }

    let root = new TreeNode(arr[0]); //根节点
    let i = 1;
    while (i < arr.length) {
        let n = 0; //每一层的节点数
        // console.log('i======', i, 'i + 2 ** n', i + 2 ** n);
        let count = 0;
        for (let j = i;
            (j < i + 2 ** n) && j < arr.length; j++) {
            console.log('element', arr[j], j);
            //添加节点
            if (arr[j] != null) {
                count++;
            }
            insertNode(root, arr[i]);
        }
        n = count;
        i += 2 ** n;
        console.log('nnn', n, i);
    }
    return root;

}

function insertNode(node, val) {
    // let flag = true;

    if (node.left == null) {
        node.left = new TreeNode(val);
    } else {
        if (node.right == null) {
            node.right = new TreeNode(val);
        } else {
            insertNode(node.right, val);
        }
        insertNode(node.left, val);
    }





}

// let array = [1, 2, null, 3, null, 4]
let array = [1, 2, 3]
console.log(JSON.stringify(convertTree(array)))

console.log('' == 0);